package cn.getech.data.development.controller;



import cn.getech.data.development.constant.ModelTypeEnum;
import cn.getech.data.development.entity.BdpDataAssetsModel;
import cn.getech.data.development.model.dto.AlgorithmDevelopmentRerunBigDataDto;
import cn.getech.data.development.service.IDataAssetsModelService;
import cn.getech.data.intelligence.common.utils.R;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 模型实时状态表 前端控制器
 * </p>
 *
 * @author zzm
 * @since 2021-01-19
 */
@RestController
@RequestMapping("/bdp/dataAssetsModel")
public class BdpDataAssetsModelController {
    @Autowired
    IDataAssetsModelService iDataAssetsModelService;

    /**
     * 获取模型类型枚举
     */
    @ApiOperation("获取所有的模型类型")
    @GetMapping("/listModelTypes")
    public R listModelTypes(){
        List<JSONObject> data = new ArrayList<>();
        for (ModelTypeEnum e : ModelTypeEnum.values()) {
                JSONObject obj = new JSONObject();
                obj.put("modelTypeId", e.getCode());
                obj.put("modelTypeName", e.getName());
                data.add(obj);
        }
        return R.okWithData(data);
    }


    /**
     * 获取所有的配置类别
     */
    @ApiOperation("根据算法和模型类别获取模型")
    @GetMapping("/selectModelsByAlgorithmTypeAndModelType")
    public R selectModelsByAlgorithmTypeAndModelType( @RequestParam Map<String,String> param){
        List<BdpDataAssetsModel> dataAssetsModels = iDataAssetsModelService.selectModelsByAlgorithmTypeAndModelType(param);
        return R.okWithData(dataAssetsModels);
    }

    /**
     * 获取所有的配置类别
     */
    @ApiOperation("选择模型和输出表的时候展示预测结果字段映射列表")
    @GetMapping("/selectReultFieldMapperList")
    public R selectReultFieldMapperList(@RequestParam String modelTypeId, @RequestParam  Integer modelId,@RequestParam Integer outputPreTableId){
        List<Map<String, Object>> reultFieldMapperList = iDataAssetsModelService.selectReultFieldMapperList(modelTypeId, modelId,outputPreTableId);
        return R.okWithData(reultFieldMapperList);
    }


    /**
     * 获取所有的配置类别
     */
    @ApiOperation("test:返回大数据算法开发的字段")
    @GetMapping("/backAlgorithmParam")
    public R returnAlgorithmDevData(Integer jobNodeId, Integer modelId){
        AlgorithmDevelopmentRerunBigDataDto algorithmDevelopmentRerunBigDataDto = iDataAssetsModelService.returnAlgorithmDevDataToBigData(jobNodeId,modelId);
        return R.okWithData(algorithmDevelopmentRerunBigDataDto);
    }


}

